package org.aplikator.server.rpc.handler;

import org.aplikator.client.data.PrimaryKey;
import org.aplikator.client.descriptor.ViewDTO;
import org.aplikator.client.descriptor.PropertyDTO;
import org.aplikator.client.rpc.impl.GetPage;
import org.aplikator.client.rpc.impl.GetPageResponse;
import org.aplikator.server.Context;
import org.aplikator.server.persistence.Persister;
import org.aplikator.server.persistence.PersisterFactory;
import org.aplikator.server.rpc.CommandHandler;

public class GetPageHandler implements CommandHandler<GetPage, GetPageResponse> {

    private Persister persister = PersisterFactory.getPersister();

    public GetPageHandler() {
    }

    public GetPageResponse execute(GetPage command, Context context) {
        ViewDTO view = command.getView();
        PropertyDTO<Integer> ownerProperty = command.getOwnerProperty();
        PrimaryKey ownerPrimaryKey = command.getOwnerPrimaryKey();
        int pageOffset = command.getPageOffset();
        int pageSize = command.getPageSize();
        return new GetPageResponse(persister.getPage(view, ownerProperty, ownerPrimaryKey, pageOffset, pageSize, context));
    }

}
